<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content">
  <div class="top">
    <div class="center">
      <h1><?php echo $heading_title; ?></h1>
    </div>
  </div>
  <div class="middle">
<div class="box">
<div class="box-heading">添加站点</div>
<div class="box-content">
      <form action="" id="site_form" method="POST">
      <tbody>
        <table class="form">
            <tr>
                <td>站点名称</td>
                <td><input type="text" id="site_name" name="site_name"  value=""/></td>
            </tr>
            <tr>
                <td>站点URL</td>
                <td><input type="text" id="site_url" name="site_url"  value="" onblur="check();"/><span id="check_site_url_msg"></span></td>
            </tr>
            <tr>
                <td>所属分类</td>
                <td>            
                <select id="cat_id" name="cat_id">
                    <?php echo $opt_category ?>
                </select></td>
            </tr>
            <tr>
                <td>账号信息</td>
                <td><textarea name="account" class="center"  ></textarea></td>
            </tr>
            <tr>
                <td>备注</td>
                <td><textarea name="other" class="center"  ></textarea></td>
            </tr>
            <tr>
                <td><input type="submit" id="site_form_submit" value="添加" class="buttons"/></td>
            </tr>
        </table>
    </tbody>
    </form>
    </div>
  </div>
  <div class="bottom">
    <div class="left"></div>
    <div class="right"></div>
    <div class="center"></div>
  </div>
</div>
<script language="javascript">
$(document).ready(function(){
    $("#site_form").submit(function(){
		var options = {
                url:        "index.php?route=site/manger/insert",
                dataType:        "json",
				beforeSubmit:  validate,  // pre-submit callback
				success:       showResponse  // post-submit callback
		};
        jQuery(this).ajaxSubmit(options);
        return false;
    });
});
function validate()
{
    var site_name = $("#site_name").val();
    var site_url = $("#site_url").val();
    if(site_name == '')
    {
        $('.success, .warning, .attention, .information').remove();
        $('#notification').html('<div class="warning" style="display: none;">网站名称不能为空<img src="home/view/image/close.png" alt="" class="close" /></div>');
        $('.warning').fadeIn('slow');
        return false;
    }    
    if(site_url == '')
    {
        $('.success, .warning, .attention, .information').remove();
        $('#notification').html('<div class="warning" style="display: none;">网站地址不能为空<img src="home/view/image/close.png" alt="" class="close" /></div>');
        $('.warning').fadeIn('slow');
        return false;
    }
    
}
function showResponse(json)
{
    $('#site_form').clearForm();
    if (json['success']) {
        $('.success, .warning, .attention, .information').remove();
        $('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="home/view/image/close.png" alt="" class="close" /></div>');
        $('.success').fadeIn('slow');
        
        $('html, body').animate({ scrollTop: 0 }, 'slow'); 
    }
    return false;
}

function check()
{
    var site_url = $("#site_url").val();
    if(site_url == '')
    {
        $("#check_site_url_msg").html('<div >网站地址不能为空</div>').fadeOut('slow');
        return false;
    }
    else
    {
        $.ajax({
        url: 'index.php?route=site/manger/checkUrlexist' + '&site_url=' + site_url +'',
        dataType: 'json',
        success: function(json) {
            if (json['success']) {
                    $('.success, .warning, .attention, .information').remove();
                    $('#notification').html('<div class="warning" style="display: none;">' + json['success'] + '<img src="home/view/image/close.png" alt="" class="close" /></div>');
                    $('.warning').fadeIn('slow');
                    $('html, body').animate({ scrollTop: 0 }, 'slow'); 
                }
            }
        });
    }
    return false;
}
</script>
<?php echo $footer; ?> 